<?php
/**
 * SEF component for Joomla! 1.5
 *
 * @author      ARTIO s.r.o.
 * @copyright   ARTIO s.r.o., http://www.artio.cz
 * @package     JoomSEF
 * @version     3.1.0
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport('joomla.application.component.model');

class SEFModelSEF extends JModel
{
    function getFeed()
    {
        $sefConfig =& SEFConfig::getConfig();
        
        if (!$sefConfig->artioFeedDisplay) {
            return '';
        }
        
        $options = array();
        $options['rssUrl'] = $sefConfig->artioFeedUrl;
        $options['cache_time'] = null;
        
        $rssDoc =& JFactory::getXMLparser('RSS', $options);
        
        if ($rssDoc == false) {
            return JText::_('COM_SEF_ERROR_CONNECTING_TO_RSS_FEED');
        }
        
        $items = $rssDoc->get_items();
        
        if (count($items) == 0) {
            return JText::_('COM_SEF_NO_ITEMS_TO_DISPLAY');
        }
        
        $txt = '';
        for ($i = 0, $n = count($items); $i < $n; $i++)
        {
            $item =& $items[$i];
            
            $title = $item->get_title();
            $link = $item->get_link();
            $desc = $item->get_description();
            $date = $item->get_date('j. F Y');
            $author = $item->get_author();
            
            $txt .= '<div class="feed-item">';
            $txt .= '<div class="feed-title"><a href="'.$link.'" target="_blank">'.$title.'</a></div>';
            $txt .= '<div class="feed-text">'.$desc.'</div>';
            $txt .= '</div>';
        }
        
        return $txt;
    }
    
    public function checkPluginsOrdering()
    {
        // Check that the language filter plugin is before JoomSEF if enabled
        if (JPluginHelper::isEnabled('system', 'languagefilter')) {
            $db = JFactory::getDbo();
            $db->setQuery("SELECT `element`, `ordering` FROM `#__extensions` WHERE `enabled` >= '1' AND `type` = 'plugin' AND `folder` = 'system' AND `state` >= '0'");
            $plgs = $db->loadObjectList('element');
            
            // Check ordering
            if (isset($plgs['joomsef']) && isset($plgs['languagefilter']) && ($plgs['languagefilter']->ordering >= $plgs['joomsef']->ordering)) {
                JError::raiseWarning(0, JText::sprintf('COM_SEF_WARNING_LANGUAGEFILTER_ORDERING', '<a href="index.php?option=com_plugins&amp;filter_folder=system">'.JText::_('COM_SEF_PLUG_IN_MANAGER').'</a>'));
            }
        }
    }
    
}

?>